﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test03
{
    static class Program
    {
        //static void Print(string info) => Console.WriteLine(info);
        delegate float CalcFunc(float val1, float val2);
        static float Add(float val1, float val2)
        {
            Console.WriteLine("{0} + {1} = {2}", val1, val2, val1 + val2);
            return val1 + val2;
        }
        static float Sub(float val1, float val2)
        {
            Console.WriteLine("{0} - {1} = {2}", val1, val2, val1 - val2);
            return val1 - val2;
        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void test01()
        {
            CalcFunc c = Add;
            c(12, 13);
            Console.WriteLine("-----");
            c += Sub;
            c(12, 13);
            Console.WriteLine("-----");
            c -= Add;
            c(12, 13);
            //c#自带两个 void Action<in T> Func<in T1,in T2,out Tresult>(T1 arg1,T2 arg2)
        }
        static void test02()
        {
            //匿名函数
            Action closure = () => {
                Console.WriteLine("匿名函数调用");
            };
            closure();
        }
        static void Main()
        {
            test01();
            test02();
        }
    }
}
